﻿using Google.Protobuf.WellKnownTypes;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using 托尔斯泰.Wishire.entity;
/*
//插入一个target_st
public void targetInsert(target_st target_St)
//根据ID删除
public void targetDelete(int ID)
//根据ID更新数据
public void targetUpdate(target_st target_St, int ID)
//根据ID查询 只查得到一个数据
public target_st targetFind(int ID)
//根据planID查询 返回一个数组
public List<target_st> targetFind_planId(int ID)
//根据城市名称查询 返回一个数组
public List<target_st> targetFind_targetCity(string Name)
//根据景点名称查询 返回一个数组
public List<target_st> targetFind_targetName(string Name)
*/
namespace 托尔斯泰.Wishire.Operator
{
    class opdatatarget
    {
        //插入一个target_st
        public void targetInsert(target_st target_St)
        {
            string targetIdStr = target_St.GetTargetId().ToString();
            string planIdStr = target_St.GetPlanId().ToString();
            string targetCityStr = target_St.GetTargetCity();
            string targetAddressStr = target_St.GetTargetAddress();
            string targetNameStr = target_St.GetTargetName();
            string targetTypeStr = target_St.GetTargetType();
            string targetLatStr = target_St.GetTargetLat().ToString();
            string targetLngStr = target_St.GetTargetLng().ToString();
            string mustNightStr = target_St.GetMustNight().ToString();
            string emptyStr = target_St.GetEmpty().ToString();
            //string temp = "insert into plan_st (planId,planName,accountId,cityName,startTime,endTime,ifDeleted,setTime,empty,hotelName,hotelLat,hotelLng) ";
            string temp = "insert into target_st ";
            string value = $"value('{targetIdStr}','{planIdStr}','{targetCityStr}','{targetAddressStr}','{targetNameStr}','{targetTypeStr}','{targetLatStr}','{targetLngStr}',";
            value += $"'{mustNightStr}','{emptyStr}')";
            string query = temp + value;
            try
            {
                MysqlOp mysqlOp = new MysqlOp();
                mysqlOp.Mysqlop(query);
                Console.WriteLine("增加成功");

            }
            catch (Exception ex)
            {
                Console.WriteLine("增加失败");
            }
        }
        //根据ID删除
        public void targetDelete(int ID)
        {
            //string temp = "insert into plan_st (planId,planName,accountId,cityName,startTime,endTime,ifDeleted,setTime,empty,hotelName,hotelLat,hotelLng) ";
            string temp = "delete from  target_st  where ";
            string value = $"targetId={ID}";
            string query = temp + value;
            try
            {
                MysqlOp mysqlOp = new MysqlOp();
                mysqlOp.Mysqlop(query);
                Console.WriteLine("删除成功");
            }
            catch (Exception ex)
            {
                Console.WriteLine("删除失败");
            }
        }
        //根据ID更新数据
        public void targetUpdate(target_st target_St, int ID)
        {
            try
            {
                targetDelete(ID);
                targetInsert(target_St);
                Console.WriteLine("修改成功");
            }
            catch (Exception ex)
            {
                Console.WriteLine("修改失败");
            }

        }
        //根据ID查询 只查得到一个数据
        public target_st targetFind(int ID)
        {
            MysqlOp mysqlOp = new MysqlOp();
            var temp = $"select * from  target_st  where targetId={ID} ";
            var ans = mysqlOp.Mysql_target_Query(temp);
            target_st target = null;
            if (ans.Count > 0) target = ans[0];
            return target;
        }
        //根据planID查询 返回一个数组
        public List<target_st> targetFind_planId(int ID)
        {
            MysqlOp mysqlOp = new MysqlOp();
            var temp = $"select * from  target_st  where planId={ID} ";
            var ans = mysqlOp.Mysql_target_Query(temp);
            return ans;
        }
        //根据城市名称查询 返回一个数组
        public List<target_st> targetFind_targetCity(string Name)
        {
            MysqlOp mysqlOp = new MysqlOp();
            var temp = $"select * from  target_st  where targetCity='{Name}'";
            var ans = mysqlOp.Mysql_target_Query(temp);
            return ans;
        }
        //根据景点名称查询 返回一个数组
        public List<target_st> targetFind_targetName(string Name)
        {
            MysqlOp mysqlOp = new MysqlOp();
            var temp = $"select * from  target_st  where targetName='{Name}'";
            var ans = mysqlOp.Mysql_target_Query(temp);
            return ans;
        }
    }
}
